package com.backend.demo1.services;

import com.backend.demo1.config.ApiException;
import com.backend.demo1.mapper.MatchCommentMapper;
import com.backend.demo1.models.Match.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MatchCommentService {

    @Autowired
    private MatchCommentMapper matchCommentMapper;

    // 创建评论
    public Comment createComment(Comment comment) {
        try {
            comment.setDatetime(new java.util.Date());
            matchCommentMapper.insertComment(comment);
            return comment;
        } catch (Exception e) {
            throw new ApiException(500, "创建评论失败: " + e.getMessage());
        }
    }


    public List<Comment> getCommentByMatchId(Long matchId) {
        try {
            List<Comment> comment = matchCommentMapper.findCommentsByMatchId(matchId);
            if (comment == null) {
                throw new ApiException(404, "评论不存在");
            }
            return comment;
        } catch (Exception e) {
            throw new ApiException(500, "获取评论失败: " + e.getMessage());
        }
    }



    // // 删除评论
    // public void deleteComment(Long matchId, String commentId) {
    //     try {
    //         Comment comment = matchCommentMapper.findCommentsByMatchId(matchId, commentId);
    //         if (comment == null) {
    //             throw new ApiException(404, "评论不存在");
    //         }
    //         matchCommentMapper.deleteCommentById(commentId);
    //     } catch (Exception e) {
    //         throw new ApiException(500, "删除评论失败: " + e.getMessage());
    //     }
    // }
}